package Fenetres;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import ClassesJava.Lieu;
import DAO.LieuxDAO;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Image;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.sql.Time;
import java.awt.event.ActionEvent;

public class Fenetre_Creer_Lieu extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_4;
	private JTextField textField_5;
	private JLabel lblH;
	private JLabel lblMin;
	private JLabel lblSec;
	private JTextField textField_3;
	private JLabel label;
	private JTextField textField_6;
	private JLabel label_1;
	private JTextField textField_7;
	private JLabel label_2;
	private Lieu lieu; 
	private LieuxDAO lieuDAO;
	private Time Hopen;
	private Time Hclose;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Fenetre_Creer_Lieu frame = new Fenetre_Creer_Lieu();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public Fenetre_Creer_Lieu() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(500,100,557,605);
		contentPane = new JPanel_Background();
		contentPane.setForeground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("  Emplacements :");
		lblNewLabel.setForeground(Color.WHITE);
		Image icon1 = new ImageIcon(this.getClass().getResource("/placeholder-on-map-paper-in-perspective.png")).getImage();
		lblNewLabel.setIcon(new ImageIcon(icon1));
		lblNewLabel.setFont(new Font("Century Gothic", Font.PLAIN, 16));
		lblNewLabel.setBounds(49, 116, 171, 29);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Nbr Emplacements :");
		lblNewLabel_1.setForeground(Color.WHITE);
		Image icon2 = new ImageIcon(this.getClass().getResource("/open-exit-door.png")).getImage();
		lblNewLabel_1.setIcon(new ImageIcon(icon2));
		lblNewLabel_1.setFont(new Font("Century Gothic", Font.PLAIN, 16));
		lblNewLabel_1.setBounds(48, 188, 219, 29);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("  Heure Ouverture :");
		lblNewLabel_2.setForeground(Color.WHITE);
		Image icon3 = new ImageIcon(this.getClass().getResource("/clock-circular-outline.png")).getImage();
		lblNewLabel_2.setIcon(new ImageIcon(icon3));
		lblNewLabel_2.setFont(new Font("Century Gothic", Font.PLAIN, 16));
		lblNewLabel_2.setBounds(49, 254, 188, 43);
		contentPane.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("  Heure Fermeture :");
		lblNewLabel_3.setForeground(Color.WHITE);
		Image icon4 = new ImageIcon(this.getClass().getResource("/clock-padlock.png")).getImage();
		lblNewLabel_3.setIcon(new ImageIcon(icon4));
		lblNewLabel_3.setFont(new Font("Century Gothic", Font.PLAIN, 16));
		lblNewLabel_3.setBounds(49, 332, 188, 43);
		contentPane.add(lblNewLabel_3);
		Image icon6 = new ImageIcon(this.getClass().getResource("/left-arrow.png")).getImage();
		
		textField = new JTextField();
		textField.setBounds(272, 116, 182, 35);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(272, 188, 182, 35);
		contentPane.add(textField_1);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(272, 262, 32, 35);
		contentPane.add(textField_2);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(272, 333, 32, 35);
		contentPane.add(textField_3);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(334, 261, 32, 35);
		contentPane.add(textField_4);
		
		textField_5 = new JTextField();
		textField_5.setColumns(10);
		textField_5.setBounds(403, 261, 32, 35);
		contentPane.add(textField_5);
		
		textField_6 = new JTextField();
		textField_6.setColumns(10);
		textField_6.setBounds(334, 332, 32, 35);
		contentPane.add(textField_6);
		
		textField_7 = new JTextField();
		textField_7.setColumns(10);
		textField_7.setBounds(403, 332, 32, 35);
		contentPane.add(textField_7);
		
		int heure = Integer.parseInt(textField_2.getText());
		int min = Integer.parseInt(textField_3.getText());
		int sec = Integer.parseInt(textField_4.getText());
		int heure1 = Integer.parseInt(textField_5.getText());
		int min1 = Integer.parseInt(textField_6.getText());
		int sec1 = Integer.parseInt(textField_7.getText());
		
		Hopen = new Time(heure,min,sec);
		Hclose = new Time(heure1,min1,sec1);
		
		
		lblH = new JLabel("H");
		lblH.setForeground(Color.WHITE);
		lblH.setBounds(314, 271, 21, 14);
		contentPane.add(lblH);
		
		lblMin = new JLabel("Min");
		lblMin.setForeground(Color.WHITE);
		lblMin.setBounds(376, 271, 46, 14);
		contentPane.add(lblMin);
		
		lblSec = new JLabel("Sec");
		lblSec.setForeground(Color.WHITE);
		lblSec.setBounds(445, 271, 46, 14);
		contentPane.add(lblSec);
		
		label = new JLabel("H");
		label.setForeground(Color.WHITE);
		label.setBounds(314, 342, 21, 14);
		contentPane.add(label);
		
		label_1 = new JLabel("Min");
		label_1.setForeground(Color.WHITE);
		label_1.setBounds(376, 342, 46, 14);
		contentPane.add(label_1);
		
		label_2 = new JLabel("Sec");
		label_2.setForeground(Color.WHITE);
		label_2.setBounds(445, 342, 46, 14);
		contentPane.add(label_2);
		
		JButton btnNewButton = new JButton("Creer");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int resultat = 0;
				int nbr = Integer.parseInt(textField.getText());
				lieu = new Lieu(textField.getText(), nbr, Hopen, Hclose);
				resultat = lieuDAO.creer_lieu(lieu);
					
					JOptionPane.showMessageDialog(null, resultat + " Lieu cre", "Resultat", JOptionPane.INFORMATION_MESSAGE);
			}
		});
		btnNewButton.setFont(new Font("Century Gothic", Font.PLAIN, 14));
		btnNewButton.setBounds(286, 459, 139, 43);
		contentPane.add(btnNewButton);
		
		JButton btnRetour = new JButton("    Retour");
		btnRetour.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnRetour.setFont(new Font("Century Gothic", Font.PLAIN, 14));
		btnRetour.setIcon(new ImageIcon(icon6));
		btnRetour.setBounds(116, 459, 139, 43);
		contentPane.add(btnRetour);
	}
}
